package admin.shell.commands;

import admin.exceptions.*;
import admin.ui.ProxyMediator;

public class CreateCommand extends ShellCommand {

	@Override
	public void execute(ProxyMediator proxy, String[] parameters) {
		if (parameters.length != 4) {
			System.out.println("Usage: create <login> <password> <role>");
			return;
		}
		
		String login = parameters[1];
		String password = parameters[2];
		String role = parameters[3];
			
		try {
			proxy.createAccount(login, password, role);
			System.out.println("Account created.");
		} catch (InvalidRoleException e) {
			System.out.println("Error: Account creation failed: Invalid role - " + role);
		} catch (UserAlreadyExistsException e) {
			System.out.println("Error: Account creation failed: User already exists");
		} catch (InsufficientPermissionsException e) {
			System.out.println("Error: Account creation failed: Insufficient permissions to create an account");
		}
	}
}
